import java.util.ArrayList;
import java.util.List;

/**
 * @program: LeetCode
 * @description: LeetCode : 228. 汇总区间
 * @author: WXY
 * @create: 2023-01-08 21:05
 * @Version 1.0
 **/
public class Num228_summaryRanges {
    public static List<String> summaryRanges(int[] nums) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            StringBuilder sb = new StringBuilder();
            int temp = i;
            while (i + 1 < nums.length && nums[i] == nums[i + 1] - 1) {
                i++;
            }
            if (i == temp) {
                sb.append(nums[i]);
            } else {
                sb.append(nums[temp]);
                sb.append("->");
                sb.append(nums[i]);
            }
            list.add(sb.toString());
        }
        return list;
    }
}
